/*
package com.dnjn.happiness.emo.assist;

import com.dnjn.happiness.emo.domain.Hlbean;
import com.dnjn.happiness.emo.domain.HlbeanType;
import com.dnjn.happiness.emo.domain.User;
import com.dnjn.happiness.emo.service.IHlbeanService;
import com.dnjn.happiness.emo.service.IHlbeanTypeService;
import com.dnjn.happiness.emo.service.IUserService;
import com.dnjn.happiness.sys.service.IHxBeanService;
import com.dnjn.happiness.system.service.ISysConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Service
public class HxBeanService implements IHxBeanService {

    private static final Logger log = LoggerFactory.getLogger(HxBeanService.class);
    @Autowired
    private IHlbeanService hlbeanService;
    @Autowired
    private IUserService userService;

    @Autowired
    private ISysConfigService configService;

    @Autowired
    private IHlbeanTypeService hlbeanTypeService;

    @Override
    public void saveEmoUser(HxBeanSeed beanSeed) {
        User user = new User()
                .setUserId(beanSeed.getUserId())
                .setHlbean(0L)
                .setHappinessScore(0L)
                .setHlbeanToday(0L);
        userService.save(user);
    }

    @Override
    public void delEmoUser(HxBeanSeed beanSeed) {
        userService.lambdaUpdate().set(User::getDeleted, "1").eq(User::getUserId, beanSeed.getUserId()).update();
    }

    @Override
    @Transactional
    public boolean updateHBean(HxBeanSeed seed) {
        Long userId = seed.getUserId();
        String code = seed.getRiskType();
        if ("true".equals(configService.selectConfigByKey("biz.happinessBean.enabled"))) {
            HlbeanType hlbeanType = hlbeanTypeService.getHlbeanTypeByCode(code);
            Integer currValue = hlbeanType.getHlbeanValue();
            User emoUser = userService.lambdaQuery().eq(User::getUserId, userId).one();
            if (null == emoUser) {
                emoUser = userService.saveEmoUser(userId);
            }
            //更新emoUser的快乐豆
            userService.lambdaUpdate()
                    .set(User::getHlbeanToday, (emoUser.getHlbeanToday() == null ? 0 : emoUser.getHlbeanToday()) + currValue)
                    .set(User::getHlbean, (emoUser.getHlbean() == null ? 0 : emoUser.getHlbean()) + currValue)
                    .eq(User::getUserId, userId).update();
            //新增hlbean记录
            Hlbean hlbean = new Hlbean().
                    setUserId(userId)
                    .setHlbeanCode(code)
                    .setCurrDatetime(LocalDateTime.now())
                    .setCurrDate(LocalDate.now())
                    .setHlbeanCurr(currValue)
                    .setHlbeanBefore(emoUser.getHlbean() == null ? 0 : emoUser.getHlbean().intValue())
                    .setHlbeanAfter((emoUser.getHlbean() == null ? 0 : emoUser.getHlbean().intValue()) + currValue);
            hlbeanService.save(hlbean);
        }
        return true;
    }
}
*/
